package com.ning.farm_income_back.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ning.farm_income_back.domain.Feedback;
import com.ning.farm_income_back.dto.FeedbackDto;
import com.ning.farm_income_back.mapper.FeedbackMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class FeedbackService {
    @Autowired
    private FeedbackMapper feedbackMapper;

    public PageInfo<FeedbackDto> getPage(FeedbackDto feedback, Integer pageNum, Integer pageSize) {
        //页面排序
        PageHelper.startPage(pageNum,pageSize,"feedback_id desc");
        List<FeedbackDto> list = feedbackMapper.selectBy(feedback);
        return new PageInfo<>(list);
    }

    public void updateFeedback(Feedback feedback) {
        feedbackMapper.updateByPrimaryKey(feedback);
    }

    public void addContent(Feedback feedback) {
        feedback.setStatus("pending");
        feedback.setSubmitTime(new Date());
        feedbackMapper.insert(feedback);
    }
}
